package com.leetcode.contest;

import java.util.HashMap;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2021/10/30 22:31
 */
public class LC5898数组中第K个独一无二的字符串 {

    public static String kthDistinct(String[] arr, int k) {
        Map<String, Integer> strTable = new HashMap<>(arr.length);
        for (String s : arr) {
            strTable.put(s, strTable.getOrDefault(s, 0) + 1);
        }
        int count = 0;
        String answer = "";
        for (String s : arr) {
            int times = strTable.get(s);
            if (times == 1) count++;
            if (count == k) {
                answer = s;
                break;
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        String[] arr = {"a", "b", "a"};
        int k = 3;
        System.out.println(kthDistinct(arr, k));
    }
}
